<template xmlns="">
	<div class="login">
		<img src="/img/computer.png" alt="" class="computer" />
		<el-form ref="loginForm" :model="loginForm" :rules="LoginRules" class="login-form">
			<h3 class="title">心电管理系统</h3>
			<el-form-item prop="username">
				<el-input v-model="loginForm.username" type="text" auto-complete="off" placeholder="账户">
					<svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
				</el-input>
			</el-form-item>
			<el-form-item prop="password">
				<el-input v-model="loginForm.password" type="password" auto-complete="off" placeholder="密码">
					<svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
				</el-input>
			</el-form-item>
			<el-checkbox v-model="loginForm.rememberMe" style="margin: 0 0 25px 0">记住密码</el-checkbox>

			<el-form-item style="width: 100%">
				<el-button round class="loginBtn" :loading="loading" size="lg" type="primary" @click.native.prevent="handleLogin">登录</el-button>
			</el-form-item>
		</el-form>
		<!--  底部  -->
		<div class="el-login-footer">
			<!-- <span>Copyright © 2018-2024 ruoyi.vip All Rights Reserved.</span> -->
		</div>
	</div>
</template>

<script>
import { getCaptchaEnable, getTenantEnable } from '@/utils/ruoyi';
import {
	getPassword,
	getRememberMe,
	getTenantName,
	getUsername,
	removePassword,
	removeRememberMe,
	removeTenantName,
	removeUsername,
	setPassword,
	setRememberMe,
	setTenantId,
	setTenantName,
	setUsername
} from '@/utils/auth';

export default {
	name: 'Login',
	data() {
		return {
			captchaEnable: false,
			tenantEnable: false,
			loginForm: {
				username: 'admin',
				password: 'admin123',
				rememberMe: false
			},
			LoginRules: {
				username: [{ required: true, trigger: 'blur', message: '用户名不能为空' }],
				password: [{ required: true, trigger: 'blur', message: '密码不能为空' }]
			},
			loading: false,
			redirect: undefined
		};
	},
	created() {
		// 重定向地址
		this.redirect = this.$route.query.redirect ? decodeURIComponent(this.$route.query.redirect) : undefined;
	},
	methods: {
		handleLogin() {
			this.$refs.loginForm.validate(valid => {
				console.log('valid', valid);
				if (valid) {
					this.loading = true;
					// 设置 Cookie
					if (this.loginForm.rememberMe) {
						setUsername(this.loginForm.username);
						setPassword(this.loginForm.password);
						setRememberMe(this.loginForm.rememberMe);
						setTenantName(this.loginForm.tenantName);
					} else {
						removeUsername();
						removePassword();
						removeRememberMe();
						removeTenantName();
					}
					this.$store
						.dispatch('Login', this.loginForm)
						.then(() => {
							this.$router.push({ path: this.redirect || '/' }).catch(() => {});
						})
						.catch(() => {
							this.loading = false;
						});
				}
			});
		}
	}
};
</script>

<style rel="stylesheet/scss" lang="scss">
.login {
	display: flex;
	justify-content: center;
	align-items: center;
	height: 100vh;
	background: url('/img/bg.jpg') center center;
	background-size: cover;
	position: relative;
}
.computer {
	position: absolute;
	width: 39.6%;
	bottom: 0;
	right: 0;
	// min-width: 594px;
}
@media (max-width: 1500px) {
	.login {
		background-size: 1500px auto;
	}
}

.title {
	margin: 0px auto 30px auto;
	text-align: center;
	color: #fff;
	font-size: 30px;
}

.login-form {
	border-radius: 6px;
	background: none;
	width: 400px;
	padding: 0 25px 5px 25px;

	.el-input {
		height: 48px;

		input {
			height: 48px;
			background: none;
			border-radius: 50px;
			color: #fff;
			padding-left: 35px;
			border-color: #07e5f2;
		}
	}

	.input-icon,
	.el-icon-date {
		height: 48px;
		width: 20px;
		margin-left: 6px;
		margin-left: 5px;
		font-size: 18px;
	}

	.loginBtn {
		background: #07e5f2;
		box-shadow: 0 0 15px rgba(7, 229, 242, 0.6);
		width: 100%;
		height: 50px;
		border: none;
		border-radius: 50px;
		font-size: 18px;
	}
	.el-checkbox {
		color: #fff;
	}
}

.login-tip {
	font-size: 13px;
	text-align: center;
	color: #bfbfbf;
}

.login-code {
	width: 33%;
	height: 38px;
	float: right;

	img {
		cursor: pointer;
		vertical-align: middle;
	}
}

.el-login-footer {
	height: 40px;
	line-height: 40px;
	position: fixed;
	bottom: 0;
	width: 100%;
	text-align: center;
	color: #fff;
	font-family: Arial;
	font-size: 12px;
	letter-spacing: 1px;
}

.login-code-img {
	height: 38px;
}
</style>
